package com.ouc.eddyAlgorithm.controller;

import com.ouc.common.annotation.Log;
import com.ouc.common.core.controller.BaseController;
import com.ouc.common.core.domain.AjaxResult;
import com.ouc.common.core.page.TableDataInfo;
import com.ouc.common.enums.BusinessType;
import com.ouc.common.utils.poi.ExcelUtil;
import com.ouc.eddyAlgorithm.domain.SysPort;
import com.ouc.eddyAlgorithm.service.ISysPortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 港口Controller
 *
 * @author ouc
 * @date 2025-06-18
 */
@RestController
@RequestMapping("/eddyAlgorithm/port")
public class SysPortController extends BaseController {
  @Autowired
  private ISysPortService sysPortService;

  /**
   * 查询港口列表
   */
  @PreAuthorize("@ss.hasPermi('eddyAlgorithm:port:list')")
  @GetMapping("/list")
  public TableDataInfo list(SysPort sysPort) {
    startPage();
    List<SysPort> list = sysPortService.selectSysPortList(sysPort);
    return getDataTable(list);
  }

  /**
   * 导出港口列表
   */
  @PreAuthorize("@ss.hasPermi('eddyAlgorithm:port:export')")
  @Log(title = "港口", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, SysPort sysPort) {
    List<SysPort> list = sysPortService.selectSysPortList(sysPort);
    ExcelUtil<SysPort> util = new ExcelUtil<SysPort>(SysPort.class);
    util.exportExcel(response, list, "港口数据");
  }

  /**
   * 获取港口详细信息
   */
  @PreAuthorize("@ss.hasPermi('eddyAlgorithm:port:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") Long id) {
    return success(sysPortService.selectSysPortById(id));
  }

  /**
   * 新增港口
   */
  @PreAuthorize("@ss.hasPermi('eddyAlgorithm:port:add')")
  @Log(title = "港口", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@RequestBody SysPort sysPort) {
    return toAjax(sysPortService.insertSysPort(sysPort));
  }

  /**
   * 修改港口
   */
  @PreAuthorize("@ss.hasPermi('eddyAlgorithm:port:edit')")
  @Log(title = "港口", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@RequestBody SysPort sysPort) {
    return toAjax(sysPortService.updateSysPort(sysPort));
  }

  /**
   * 删除港口
   */
  @PreAuthorize("@ss.hasPermi('eddyAlgorithm:port:remove')")
  @Log(title = "港口", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable Long[] ids) {
    return toAjax(sysPortService.deleteSysPortByIds(ids));
  }
}
